package face.pay.web.withdraw.service.impl;

import face.pay.dao.OemAccountConfigDao;
import face.pay.entity.OemAccountConfig;
import face.pay.entity.UserInfo;
import face.pay.util.ResultMessage;
import face.pay.web.withdraw.service.IOemAccountConfigService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class OemAccountConfigService implements IOemAccountConfigService {


    @Autowired
    private OemAccountConfigDao oemAccountConfigDao;


    /**
     * 查询oem提现配置信息
     *
     * @param loginUser
     * @return
     */
    @Override
    public OemAccountConfig queryOemConfig(UserInfo loginUser) {
        OemAccountConfig record = new OemAccountConfig();
        record.setOemId(loginUser.getOemId());
        OemAccountConfig config = this.oemAccountConfigDao.queryOemAccountConfig(record);
        if (config == null) {
            OemAccountConfig oemAccountConfig = new OemAccountConfig();
            oemAccountConfig.setOemId(loginUser.getOemId());
            oemAccountConfig.setCreatedBy(loginUser.getId());
            this.oemAccountConfigDao.insert(oemAccountConfig);
            return oemAccountConfig;
        } else {
            return config;
        }
    }

    /**
     * 更改oem提现配置信息
     *
     * @param oemConfig
     * @param loginUser
     * @return
     */
    @Override
    public ResultMessage updateOemConfig(OemAccountConfig oemAccountConfig, UserInfo loginUser) {

        oemAccountConfig.setUpdatedBy(loginUser.getId());
        this.oemAccountConfigDao.update(oemAccountConfig);

        return ResultMessage.createSuccess();
    }
}
